package com.wzvtc.mock_service.controller;

import com.alibaba.fastjson2.JSON;
import com.apifan.common.random.source.NumberSource;
import com.apifan.common.random.source.PersonInfoSource;
import com.wzvtc.mock_service.entity.Goods;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 蔡顺达
 * @desc 模拟大数据竞赛相关RESTFul服务接口
 * @see https://blog.csdn.net/weixin_51309915/article/details/123349773
 */
@RestController
@RequestMapping("/BigDataMatch")
public class BigDataMatchMockService {


    /**
     * 这个接口不要改，要新增restful请求，自己新增方法即可
     * @return
     */
    @RequestMapping("/getGoodsList")
    public String getGoodsList(){
        List<Goods> goodsList = new ArrayList<>();
        // 模拟10个商品数据，具体要多少个，自己改
        for (int i = 0; i < 10; i++) {
            Goods goods = new Goods();
            goods.setId(i);
            // 数据模拟参考 https://www.cnblogs.com/hlmy/p/16640635.html
            goods.setName(PersonInfoSource.getInstance().randomChineseName());
            goods.setPrice(NumberSource.getInstance().randomDouble(0.01D, 100D));
            goodsList.add(goods);
        }
        return JSON.toJSONString(goodsList);
    }
}
